<!--商品数据统计-->
<template>
  <div id="product" ref="product"></div>
</template>
<script>
export default {
  name: "MyLine",
  methods: {
    drawLine() {
      let myLine = this.$echarts.init(this.$refs.product);
      let option = {
        color: ["rgb(103,102,107)", "rgb(47,0,180)"],
        title: {
          text: "商品数据统计",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          show: false,
        },
        toolbox: {
          show: false,
        },
        grid: {
          left: "5%",
          right: "10%",
          bottom: "0%",
          top: "20%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            axisLabel: {
              show: true,
              color: "#989898",
            },
            axisLine: {
              lineStyle: {
                color: "rgb(56,56,56)", //刻度线的颜色
              },
            },
            data: ["2021-04-20 00:00:00", "2021-04-22 00:00:00"],
          },
        ],
        yAxis: [
          {
            type: "value",
            // y轴网格线
            splitLine: {
              lineStyle: {
                color: "rgba(157,157,157,0.56)",
              },
            },
            axisLabel: {
              show: true,
              color: "#2c2c2c",
            },
            axisLine: {
              show: true, //是否显示轴线
              lineStyle: {
                color: "rgb(56,56,56)", //刻度线的颜色
              },
            },
            // 是否显示刻度线
            axisTick: {
              show: true,
            },
          },
        ],
        series: [
          {
            name: "销售额",
            type: "line",
            smooth: true,
            symbol: "circle",
            colorBy: "series",
            showSymbol: false,
            areaStyle: {
              opacity: 0.8,
              color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: "rgba(34,0,255,0.8)",
                },
                {
                  offset: 1,
                  color: "rgba(101,0,194,0.8)",
                },
              ]),
            },
            lineStyle: {
              width: 0.8,
            },
            emphasis: {
              focus: "series",
            },
            data: [10, 2],
          },
        ],
      };
      myLine.setOption(option);
      window.onresize = function () {
        myLine.resize();
      };
    },
  },
  mounted() {
    setTimeout(() => {
      this.drawLine();
    }, 500);
  },
};
</script>
<style scoped>
.echarts_line {
  width: 50%;
  margin: 25px 0;
}

#product {
  width: 100%;

  height: 30vh;
}
</style>
